package com.example.administrator.School;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.example.administrator.School.common.result.Result;
import com.example.administrator.School.until.BaseDetailActivity;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 值日表
 */
public class DutyActivity extends BaseDetailActivity<Map> {

    @BindView(R.id.gridview1)
    public GridView gridView;
    @BindView(R.id.gridview2)
    public GridView gridView2;

    private List<Map<String, Object>> dataList;
    private List<Map<String, Object>> dataList1;
    private SimpleAdapter adapter;
    private SimpleAdapter adapter1;
    @Override
    protected int getContentView() {
        return R.layout.activity_duty;
    }

    @Override
    protected boolean initBundle(Bundle bundle) {
        return true;
    }

    //页面传值回调
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }

    @Override
    public void initWidget() {
        super.initWidget();
        gridView = (GridView) findViewById(R.id.gridview1);
        gridView2 = (GridView) findViewById(R.id.gridview2);
        //初始化数据
        initDatas();

        String[] from={"img","text"};

        int[] to={R.id.img,R.id.text};

        adapter=new SimpleAdapter(this, dataList, R.layout.duty_gridview_item, from, to);

        adapter1=new SimpleAdapter(this, dataList1, R.layout.duty_gridview_item, from, to);

        gridView.setAdapter(adapter);

        gridView2.setAdapter(adapter1);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                AlertDialog.Builder builder= new AlertDialog.Builder(DutyActivity.this);
                builder.setTitle("提示").setMessage(dataList.get(arg2).get("text").toString()).create().show();
            }
        });

        gridView2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                AlertDialog.Builder builder= new AlertDialog.Builder(DutyActivity.this);
                builder.setTitle("提示").setMessage(dataList1.get(arg2).get("text").toString()).create().show();
            }
        });
    }


    void initDatas() {
        //图标
        int icno[] = { R.drawable.tx, R.drawable.tx, R.drawable.tx,
                R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx,
                R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx };
        //图标下的文字
        String name[]={"糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂"};
        dataList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i <icno.length; i++) {
            Map<String, Object> map=new HashMap<String, Object>();
            map.put("img", icno[i]);
            map.put("text",name[i]);
            dataList.add(map);
        }


        //图标
        int icno1[] = { R.drawable.tx, R.drawable.tx, R.drawable.tx,
                R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx,
                R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx };
        //图标下的文字
        String name1[]={"糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂","糊糊涂涂"};
        dataList1 = new ArrayList<Map<String, Object>>();
        for (int i = 0; i <icno1.length; i++) {
            Map<String, Object> map=new HashMap<String, Object>();
            map.put("img", icno1[i]);
            map.put("text",name1[i]);
            dataList1.add(map);
        }
    }


    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected Type getType() {
        return new TypeToken<Result<Map>>() {
        }.getType();
    }

    @Override
    protected void setData(Result<Map> result) {

    }

    @OnClick(R.id.close)
    void close(){
        finish();
    }
}

